package com.aigou.admin.service.impl;

import com.aigou.admin.dao.BrandDao;

import com.aigou.admin.dao.impl.BrandDaoImpl;


import com.aigou.admin.entity.Brand;

import com.aigou.admin.entity.PageEntity;

import com.aigou.admin.service.BrandService;
import lombok.AllArgsConstructor;
import org.springframework.stereotype.Service;

import java.util.List;


/**
 * @author chai
 * @date 2024/12/4 0004
 * @Description
 */
@Service
@AllArgsConstructor
public class BrandServiceImpI implements BrandService {

    private final BrandDao brandDao;


    @Override
    public List<Brand>findAll() {
        return brandDao.selectAll();
    }

    @Override
    public Brand findById(String id) {
        return brandDao.selectById(id);
    }

    @Override
    public Boolean save(Brand brand) {
        return brandDao.insert(brand);
    }

    @Override
    public Boolean update(Brand brand) {
        return brandDao.update(brand);
    }

    @Override
    public Boolean remove(String id) {
        return brandDao.delete(id);
    }

    @Override
    public PageEntity<Brand> findBrandsByPage(Integer currentPage, Integer pageSize) {
        Integer total=brandDao.selectCount();
        List <Brand> brands=brandDao.selectBrandByLimit((currentPage-1)*pageSize,pageSize);
        PageEntity<Brand> pageEntity=new PageEntity<>();
        pageEntity.setTotal(total);
        pageEntity.setPageSize(pageSize);
        pageEntity.setCurrent(currentPage);
        pageEntity.setRecords(brands);
        return pageEntity;
    }

}
